#include "MyTestScene.h"

namespace mp_myApp
{
		MyTestScene::MyTestScene()
			:GLAppScene()
		{
			m_quitEvent.reset( new GLKeyboardEvent() );
			m_pKey.reset( new GLKeyboardEvent() );/*
			m_console = new GLConsole();*/
		}


		void MyTestScene::Initialize()
		{
			//Initialize the quit button
			((GLKeyboardEvent*)(&*m_quitEvent))->SetKey(GLFW_KEY_ESCAPE);
			m_ac->m_glInput->GetInputEventCollection()->push_back(m_quitEvent);
			//Initialize test 'p' key
			((GLKeyboardEvent*)(&*m_pKey))->SetKey(GLFW_KEY_P);
			m_ac->m_glInput->GetInputEventCollection()->push_back(m_pKey);

			//if (m_ac->m_errorHandler != NULL)
			//{
				//ErrorEvent* consoleErrorEvent = new ErrorEvent();
				//m_ac->m_errorHandler->AddErrorEventListener(consoleErrorEvent);
				/*m_console->SetErrorEvent(consoleErrorEvent);*/
			//}

			//m_console->SetInputHandler(m_ac->m_glInput);
			//m_console->SetFont("Resources/Fonts/font.bff");
			//m_console->SetWindow(m_ac->m_glWindow->GetWindow());
			//m_console->Initialize();

			////Play audio test
			//

			////Load Font
			//if(!m_font->Load("Resources/Fonts/font.bff"))
			//{
			//	printf("> !! Error Loading Test Font!\n");
			//	delete m_font;
			//	m_font = NULL;
			//}
			//else
			//	m_font->SetColor(0.6f,1.0f,0.4f,1.0f);

			////Load Font
			//if(!m_fancyFont->Load("Resources/Fonts/fancy.bff"))
			//{
			//	printf("> !! Error Loading Fancy Font!\n");
			//	delete m_fancyFont;
			//	m_fancyFont = NULL;
			//}
			//else
			//	m_fancyFont->SetColor(0.6f,1.0f,0.4f,1.0f);

			m_initialized = true;

		}

		void MyTestScene::Uninitialize()
		{

			m_running = false;
			m_initialized = false;
		}

		void MyTestScene::LoadContent()
		{
			//m_console->LoadContent();
			m_contentLoaded = true;
		}

		void MyTestScene::UnloadContent()
		{
			//m_console->UnloadContent();
			m_visible = false;
			m_contentLoaded = false;
		}

		void MyTestScene::Update()
		{
			//m_console->Update();
			//Quit event
			if (m_quitEvent->IsTriggered())
				glfwSetWindowShouldClose(m_ac->m_glWindow->GetWindow(), true);
			//if (m_pKey->IsTriggered())
				//m_ac->m_errorHandler->WriteError("P Pressed");
		}

		void MyTestScene::UpdateLogic()
		{

		}

		void MyTestScene::Draw()
		{



		//if(m_font != NULL){

		//	glMatrixMode(GL_PROJECTION);
		//	glLoadIdentity();
		//	glOrtho(0,1024,0,768,-1,1);
		//	glMatrixMode(GL_MODELVIEW);
		//	glLoadIdentity();

		//	glEnable(GL_TEXTURE_2D);
		//	m_font->Bind();
		//	
		//	glEnable(GL_BLEND); // We know this is a 32bit font so set blending to suit
		//	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

		//	glColor3f(1.0f,1.0f,1.0f);

		//	m_font->SetCursor(400,250);
		//	m_font->Print("Mitchell's OpenGL Test", 0, 700);
		//	
		//	m_font->Print(" <( ',' <)", 0, 500);
		//}
		//
		//if(m_fancyFont != NULL){

		//	glMatrixMode(GL_PROJECTION);
		//	glLoadIdentity();
		//	glOrtho(0,1024,0,768,-1,1);
		//	glMatrixMode(GL_MODELVIEW);
		//	glLoadIdentity();

		//	glEnable(GL_TEXTURE_2D);
		//	m_fancyFont->Bind();
		//	
		//	glEnable(GL_BLEND); // We know this is a 32bit font so set blending to suit
		//	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

		//	glColor3f(1.0f,1.0f,1.0f);

		//	m_fancyFont->SetCursor(400,250);
		//	m_fancyFont->Print("I'm a Fancy Font!", 256, 500);
		//	
		//}
			float ratio;
			int width, height;

			glfwGetFramebufferSize(m_ac->m_glWindow->GetWindow(), &width, &height);
			ratio = width / (float) height;

			glViewport(0, 0, width, height);
			glClear(GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();

			glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glRotatef((float) glfwGetTime() * 50.f, 25.0f, 25.f, 1.f);
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_TRIANGLES);
			glColor3f(1.f, 0.f, 0.f);
			glVertex3f(-0.6f, -0.4f, 0.f);
			glColor3f(0.f, 1.f, 0.f);
			glVertex3f(0.6f, -0.4f, 0.f);
			glColor3f(0.f, 0.f, 1.f);
			glVertex3f(0.f, 0.6f, 0.f);
			glEnd();
			//m_console->Draw();
		}
}